Ext.define('cceaf.control.sms.SelectPhraseTree',{
    extend: 'Ext.Panel', 
    alias: 'widget.selectphrasetree',

    constructor: function(config){
        config = config || {};

        var tree = new Ext.tree.Panel({
            id:'selectPhraseTree',
	        //el:'tree-div',
	        autoScroll:true,
	        animate:true,
	        enableDD:true,
	        containerScroll: true,
	        //width:150,
	        anchor:'100% -30',
	        listeners:{
       		'itemclick':function(view,record){
                var selectPhraseTree = Ext.get("selectPhraseTree");
                if(selectPhraseTree.idOfNodeid != null && selectPhraseTree.idOfNodeid != ""){
                    var nodeid = Ext.getCmp(selectPhraseTree.idOfNodeid);
     				nodeid.setValue(record.data.id);
                }
                if(selectPhraseTree.idOfNodename != null && selectPhraseTree.idOfNodename != ""){
    				var nodename = Ext.getCmp(selectPhraseTree.idOfNodename);
    				nodename.setValue(record.data.text);
      		    }
			           	
           	    var selectPhraseWin = Ext.getCmp('selectPhraseWin');
                if(selectPhraseWin){
    				selectPhraseWin.hide();
                }
      		}},
	        
	        root: {
	            expanded: true,
	            text: '短语库',
		        draggable:false,
		        id:''
	        },
	        
	        store: new Ext.data.TreeStore({
	            proxy: {
	                type: 'ajax',
	                url: '/' + cceaf.Global.WEB_APP_NAME + '/smsmanager/findTreeNodeListPhrase.action'
	            },
	            sorters: [{property: 'leaf',
				          direction: 'ASC'
				      }, {
				          property: 'text',
				          direction: 'ASC'
				        }
				      ]
	        })
	    });
    
	    //groupTree.setRootNode(groupRoot);
	    
	    var operateArea = new Ext.Panel({
	        //title: '',
	        width:150,
	        anchor:'100%',
	        layout:'column',
	        items:[{xtype: 'button',text: ' 关  闭 ',pressed: true,width: 70,handler: function(){
			      		var selectPhraseWin = Ext.getCmp('selectPhraseWin');
					    if(selectPhraseWin){
					    		selectPhraseWin.hide();
					    }
	            }},
	            {html: '',width: 10},
	            {xtype: 'button',text: ' 清  空 ',pressed: true,width: 70,
	            		handler: function(){
	               		var selectPhraseTree = Ext.get("selectPhraseTree");
	               		if(selectPhraseTree.idOfNodeid != null && selectPhraseTree.idOfNodeid != ""){
	        				var nodeid = Ext.getCmp(selectPhraseTree.idOfNodeid);
	        				nodeid.setValue("");
	    	        	}
    	        		if(selectPhraseTree.idOfNodename != null && selectPhraseTree.idOfNodename != ""){
	        				var nodename = Ext.getCmp(selectPhraseTree.idOfNodename);
	        				nodename.setValue("");
    	        		}
								    	
	              		var selectPhraseWin = Ext.getCmp('selectPhraseWin');
		    			if(selectPhraseWin){
		    					selectPhraseWin.hide();
		    			}
	              	}
	            }]
	    });

		//Ext.applyIf(this, {
		config = Ext.applyIf(config || {}, {
	        layout:'anchor',
	        //anchorSize: {width:200, height:600},
	        autoScroll:true,
	        items:[operateArea,tree]
		});

		cceaf.control.sms.SelectPhraseTree.superclass.constructor.apply(this, arguments);
		
		//展开根节点
		//groupRoot.expand();
	}
});
